/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.


See LICENSE and AUTHORS for more information.
*/

#ifndef BUDDYMODEL_H
#define BUDDYMODEL_H
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>

class BuddyItem;

/**
* @class BuddyModel
* @brief the model containing all information about groups and buddies
*
* BuddyModel stores all groups and buddies after they've been received from the core.
* This includes, but is not limited to, each buddys name,jid,current status text,
* status icon as well as the account id it is associated with.
* Furthermore, all buddies are categorized in groups which so far contain a name and icon column only.
*
* The Model represents a hierarchical tree-structure for use with QTreeView. It is designed to be
* filled with items of type BuddyItem.
*/
class BuddyModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    BuddyModel(QObject *parent = 0);
    ~BuddyModel();

    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;

    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &index) const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    Qt::ItemFlags flags(const QModelIndex &index) const;
    bool setData(const QModelIndex &index, const QVariant &value,
                 int role = Qt::EditRole);
    bool setHeaderData(int section, Qt::Orientation orientation,
                       const QVariant &value, int role = Qt::EditRole);

    bool insertColumns(int position, int columns,
                       const QModelIndex &parent = QModelIndex());
    bool removeColumns(int position, int columns,
                       const QModelIndex &parent = QModelIndex());
    bool insertRows(int position, int rows,
                    const QModelIndex &parent = QModelIndex());
    bool removeRows(int position, int rows,
                    const QModelIndex &parent = QModelIndex());

    void addGroup(QString);
    void addBuddy(QString,QString,QString,int);
    QString getBuddyName(int accid,QString jid);


private:
    BuddyItem *getItem(const QModelIndex &index) const;
    BuddyItem *rootItem;
};

#endif

